package l1j.server.server.datatables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import l1j.server.L1DatabaseFactory;
import l1j.server.server.utils.SQLUtil;
import l1j.server.server.utils.collections.Maps;

public class EnchantSuccessChance {
	private static EnchantSuccessChance _instance;

	public static EnchantSuccessChance getInstance() {
		return _instance;
	}

	public static void initilize() {
		_instance = new EnchantSuccessChance();
	}

	private Map<Integer, SuccessEnchantChance> _allChances = Maps.newMap();

	private EnchantSuccessChance() {
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = L1DatabaseFactory.getInstance().getConnection();
			pstm = con.prepareStatement("SELECT * FROM enchant_success_chance");

			rs = pstm.executeQuery();
			while (rs.next()) {
				SuccessEnchantChance se = new SuccessEnchantChance();
				se.setWeapon_normal_chance(rs.getInt("weapon_normal_chance"));
				se.setWeapon_bless_1_chance(rs.getInt("weapon_bless_1_chance"));
				se.setWeapon_bless_2_chance(rs.getInt("weapon_bless_2_chance"));
				se.setWeapon_bless_3_chance(rs.getInt("weapon_bless_3_chance"));
				se.setArmor_normal_chance(rs.getInt("armor_normal_chance"));
				se.setArmor_bless_1_chance(rs.getInt("armor_bless_1_chance"));
				se.setArmor_bless_2_chance(rs.getInt("armor_bless_2_chance"));
				se.setArmor_bless_3_chance(rs.getInt("armor_bless_3_chance"));
				se.setAccessory_normal_chance(rs.getInt("accessory_normal_chance"));
				se.setAccessory_bless_1_chance(rs.getInt("accessory_bless_1_chance"));
				se.setAccessory_bless_2_chance(rs.getInt("accessory_bless_2_chance"));
				se.setAccessory_bless_3_chance(rs.getInt("accessory_bless_3_chance"));
				_allChances.put(rs.getInt("enchant_level"), se);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	public SuccessEnchantChance getChance(int enchantLevel) {
		SuccessEnchantChance sec = _allChances.get(enchantLevel);
		if (sec == null) {
			_allChances.put(enchantLevel, new SuccessEnchantChance());
			return _allChances.get(enchantLevel);
		}
		return sec;
	}

	public class SuccessEnchantChance {
		private int weapon_normal_chance = 0;
		private int weapon_bless_1_chance = 0;
		private int weapon_bless_2_chance = 0;
		private int weapon_bless_3_chance = 0;
		private int armor_normal_chance = 0;
		private int armor_bless_1_chance = 0;
		private int armor_bless_2_chance = 0;
		private int armor_bless_3_chance = 0;
		private int accessory_normal_chance = 0;
		private int accessory_bless_1_chance = 0;
		private int accessory_bless_2_chance = 0;
		private int accessory_bless_3_chance = 0;

		public int getWeapon_normal_chance() {
			return weapon_normal_chance;
		}
		
		public void setWeapon_normal_chance(int weapon_normal_chance) {
			this.weapon_normal_chance = weapon_normal_chance;
		}
		
		public int getWeapon_bless_1_chance() {
			return weapon_bless_1_chance;
		}
		
		public void setWeapon_bless_1_chance(int weapon_bless_1_chance) {
			this.weapon_bless_1_chance = weapon_bless_1_chance;
		}
		
		public int getWeapon_bless_2_chance() {
			return weapon_bless_2_chance;
		}

		public void setWeapon_bless_2_chance(int weapon_bless_2_chance) {
			this.weapon_bless_2_chance = weapon_bless_2_chance;
		}

		public int getWeapon_bless_3_chance() {
			return weapon_bless_3_chance;
		}

		public void setWeapon_bless_3_chance(int weapon_bless_3_chance) {
			this.weapon_bless_3_chance = weapon_bless_3_chance;
		}

		public int getArmor_normal_chance() {
			return armor_normal_chance;
		}

		public void setArmor_normal_chance(int armor_normal_chance) {
			this.armor_normal_chance = armor_normal_chance;
		}

		public int getArmor_bless_1_chance() {
			return armor_bless_1_chance;
		}

		public void setArmor_bless_1_chance(int armor_bless_1_chance) {
			this.armor_bless_1_chance = armor_bless_1_chance;
		}

		public int getArmor_bless_2_chance() {
			return armor_bless_2_chance;
		}

		public void setArmor_bless_2_chance(int armor_bless_2_chance) {
			this.armor_bless_2_chance = armor_bless_2_chance;
		}

		public int getArmor_bless_3_chance() {
			return armor_bless_3_chance;
		}

		public void setArmor_bless_3_chance(int armor_bless_3_chance) {
			this.armor_bless_3_chance = armor_bless_3_chance;
		}

		public int getAccessory_normal_chance() {
			return accessory_normal_chance;
		}

		public void setAccessory_normal_chance(int accessory_normal_chance) {
			this.accessory_normal_chance = accessory_normal_chance;
		}

		public int getAccessory_bless_1_chance() {
			return accessory_bless_1_chance;
		}

		public void setAccessory_bless_1_chance(int accessory_bless_1_chance) {
			this.accessory_bless_1_chance = accessory_bless_1_chance;
		}

		public int getAccessory_bless_2_chance() {
			return accessory_bless_2_chance;
		}

		public void setAccessory_bless_2_chance(int accessory_bless_2_chance) {
			this.accessory_bless_2_chance = accessory_bless_2_chance;
		}

		public int getAccessory_bless_3_chance() {
			return accessory_bless_3_chance;
		}

		public void setAccessory_bless_3_chance(int accessory_bless_3_chance) {
			this.accessory_bless_3_chance = accessory_bless_3_chance;
		}
	}
}
